<template>
  <header class="header">
    <h1>todos</h1>
    <input v-model="isAll" id="toggle-all" class="toggle-all" type="checkbox" >
    <label for="toggle-all"></label>
    <input
    v-model="text"
    @keydown.enter="addTask(text) , text = ''"
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
    />
  </header>
</template>

<script>
import { mapMutations, mapGetters } from 'vuex'

export default {
  data () {
    return {
      text: ''
    }
  },
  methods: {
    ...mapMutations('todo', ['addTask', 'updateIsDone'])
  },
  computed: {
    ...mapGetters('todo', ['showList']),
    isAll: {
      set (val) {
        this.updateIsDone(val)
      },
      get () {
        return this.showList.every(item => item.isDone)
      }
    }
  }
}
</script>
